<?
	$page["title"] = "Status of triggers";
	$page["file"] = "tr_status.html";

	include "include/config.inc";
	show_header($page["title"],10);
?>                                                                                                             

<?
	show_table_header_begin();
	echo "STATUS OF TRIGGERS";


        show_table_v_delimiter();
?>
 
<?
        $result=DBselect("select hostid,host from hosts order by host");
        if(isset($hostid))
        {
                echo "<A HREF=\"tr_status.html\">all</A>  ";
        }
        else
        {
                echo "<b>[<A HREF=\"tr_status.html\">all</A>]</b>  ";
        }
	for($i=0;$i<DBnum_rows($result);$i++)
        {
                $hid=DBget_field($result,$i,0);
                $host=DBget_field($result,$i,1);
                if($hid == $hostid)
                {
                        echo "<b>[<A HREF=\"tr_status.html?hostid=$hid\">$host</A>]</b>  ";
                }
                else
                {
                        echo "<A HREF=\"tr_status.html?hostid=$hid\">$host</A>  ";
                }
        }
 
	show_table_v_delimiter();
?>

<A NAME="top"></A>
<?
	if($noactions!='true')
	{
		$noactions='false';
	}
?>

<?
	if($onlytrue!='true')
	{
		echo "[<A HREF=\"tr_status.html?onlytrue=true&noactions=$noactions&compact=$compact\">Show only true</a>] ";
		$onlytrue='false';
	}
	else
	{
		echo "[<A HREF=\"tr_status.html?noactions=$noactions&compact=$compact\">Show all triggers</A>] ";
	}
	if($noactions!='true')
	{
		echo "[<A HREF=\"tr_status.html?onlytrue=$onlytrue&noactions=true&compact=$compact\">Hide Actions</A>] ";
	}
	else
	{
		echo "[<A HREF=\"tr_status.html?onlytrue=$onlytrue&noactions=false&compact=$compact\">Show Actions</A>] ";
	}
	if($compact!='true')
	{
		echo "[<A HREF=\"tr_status.html?onlytrue=$onlytrue&noactions=$noactions&compact=true\">Hide Details</A>] ";
	}
	else
	{
		echo "[<A HREF=\"tr_status.html?onlytrue=$onlytrue&noactions=$noactions&compact=false\">Show Details</A>] ";
	}
  
	show_table_header_end();
	
	echo "<br>";
   
	show_table_header("TRIGGERS");
  
	echo "\n<TABLE BORDER=0 COLS=5 WIDTH=\"100%\" BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>";
	echo "<TR ALIGN=CENTER>";
	echo "<TD ALIGN=LEFT><B>Description";
	if($compact!='true') {echo "<BR><FONT SIZE=-1>Expression</FONT></B>";}
	echo "</TD>";
	echo "<TD WIDTH=\"3%\"><B>Status</B></TD>";
	echo "<TD WIDTH=\"3%\"><B>Priority</B></TD>";
	if($noactions=='true')
		echo "<TD WIDTH=\"12%\">";
	else
		echo "<TD WIDTH=\"3%\">";

	echo "<B>Last change";
	if($compact!='true') { echo "<BR><FONT SIZE=-1>(Last check)</FONT></B>";}
	echo "</TD>";
   
	if($noactions!='true')
	{  
		echo "<TD WIDTH=\"8%\" NOSAVE><B>Actions</B></TD>";
	}
	echo "</TR>\n";

	if(isset($hostid))
	{
		$cond=" and h.hostid=$hostid ";
	}
	else
	{
		$cond="";
	}


	if($onlytrue=='true')
	{
		$result=DBselect("select t.triggerid,t.istrue,t.description,t.lastcheck,t.expression,t.priority,t.lastchange,t.comments from triggers t,hosts h,items i,functions f  where t.istrue=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid $cond order by t.priority desc, t.description");
	}
	else
	{
		$result=DBselect("select t.triggerid,t.istrue,t.description,t.lastcheck,t.expression,t.priority,t.lastchange,t.comments from triggers t,hosts h,items i,functions f  where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid $cond order by t.priority desc, t.description");
	}
	for($i=0;$i<DBnum_rows($result);$i++)
	{
		if($col==1)
		{
			echo "\n<TR BGCOLOR=#EEEEEE>";
			$col=0;
		} else
		{
			echo "\n<TR BGCOLOR=#DDDDDD>";
			$col=1;
		}
		$expression=DBget_field($result,$i,4);
		$description=DBget_field($result,$i,2);
		$triggerid=DBget_field($result,$i,0);
		$istrue=DBget_field($result,$i,1);
		$lastcheck=DBget_field($result,$i,3);
		$priority=DBget_field($result,$i,5);
		$lastchange=DBget_field($result,$i,6); 
		$comments=DBget_field($result,$i,7);
 
		$lastchange=date("d M H:i:s",$lastchange);

		echo "<TD>";

		if(($comments!="")&&($comments!=" "))
		{
			echo "<A HREF=\"comments.html?triggerId=$triggerid\"><b>C</b></a>  &nbsp;";
		}  
		echo "$description";

		if($compact!='true')
		{
			$expression=explode_exp($expression,1);
			echo "<BR><FONT COLOR=\"#000000\" SIZE=-2>$expression</FONT>";
		}
		echo "</TD>";
		if($istrue==0)
		{ echo "<TD ALIGN=CENTER><FONT COLOR=\"00AA00\">FALSE</FONT></TD>";}
		elseif($istrue==2)
		{ echo "<TD ALIGN=CENTER><FONT COLOR=\"777777\">DISABLED</FONT></TD>";  }
		elseif($istrue==3)
		{ echo "<TD ALIGN=CENTER><FONT COLOR=\"777777\">MODIFIED</FONT></TD>";  }
		else 
		{  echo "<TD ALIGN=CENTER><FONT COLOR=\"AA0000\">TRUE</FONT></TD>"; }

		if($priority==0)	echo "<TD ALIGN=CENTER>Not clasified</TD>";
		elseif($priority==1)	echo "<TD ALIGN=CENTER>Just information</TD>";
		elseif($priority==2)	echo "<TD ALIGN=CENTER>Warning</TD>";
		elseif($priority==3)	echo "<TD ALIGN=CENTER BGCOLOR=#DDAAAA>Average</TD>";
		elseif($priority==4)	echo "<TD ALIGN=CENTER BGCOLOR=#FF8888>High</TD>";
		elseif($priority==5)	echo "<TD ALIGN=CENTER BGCOLOR=RED>Disaster !!!</TD>";
		else			echo "<TD ALIGN=CENTER><B>$priority</B></TD>";

		echo "<TD ALIGN=CENTER><A HREF=\"alarms.html?triggerid=$triggerid\">$lastchange</a>";
		if($compact!='true')
		{ 
			echo "<BR><FONT SIZE=-1 COLOR=BLACK>(",date("H:i:s",$lastcheck),")</FONT>";
		}
		echo "</TD>";

		if($noactions!='true')
		{
			echo "<TD>";
			echo "<A HREF=\"actions.html?triggerid=$triggerid\">Show actions</A> - ";
			echo "<A HREF=\"alarms.html?triggerid=$triggerid\">History</A>";
			echo "</TD>";
		}
		if($istrue==0)	echo "</TR>\n";
	}
	echo "</TABLE>\n";

	$i=DBnum_rows($result);

	show_table_header("Total:$i");

	$result=DBselect("select min(lastcheck) from triggers where istrue<2");
	$lastcheck=DBget_field($result,0,0);
	$diff=mktime()-$lastcheck; 

	$now=time();
	$result=DBselect("select count(*) from items i,hosts h where i.status=0 and h.status=0 and h.hostid=i.hostid and i.nextcheck<$now-60");
	$answ=DBget_field($result,0,0);
	if ($answ>0)
	{ 
		echo "<br>";
		show_table_header("<font color=\"AA0000\">Is zabbix_sucker running ? Check QUEUE.</font>");
	}

	if(($lastcheck!=NULL)&&($diff>180)) ### Result for Trigger checking
	{
		echo "<br>";
		show_table_header("<font color=\"AA0000\">Is zabbix_alarmer running ?</font>");
	}
?>

<?
	show_footer();
?>
